package com.eims.ball.info.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import bls.juejin.cn.R;
import progressBar.ProgressDialogBar;


public class PeilvTwoFragment extends Fragment implements OnClickListener {

	private Activity activity;
	private TextView tvOupei, tvYapan, tvDaxia, tvKaili;
	public int tvId;
	private String infoId,hid,gid, mainName, GuesName;



	public PeilvTwoFragment() {
		super();
	}

	public static PeilvTwoFragment newInstance(String infoId,String hid,String gid,String mainName,String GuesName) {

		Bundle args = new Bundle();

		PeilvTwoFragment fragment = new PeilvTwoFragment();
		args.putString("infoId",infoId);
		args.putString("hid",hid);
		args.putString("gid",gid);
		args.putString("mainName",mainName);
		args.putString("GuesName",GuesName);
		fragment.setArguments(args);
		return fragment;
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.peilv_fragment, container, false);
		activity = getActivity();
		Bundle args = getArguments();
		if (args != null) {
			this.infoId = args.getString("infoId");
			this.hid= args.getString("hid");
			this.gid = args.getString("gid");
			this.mainName= args.getString("mainName");
			this.GuesName= args.getString("GuesName");

		}
		init(view);

		changeFragment(1);
		return view;
	}

	private void init(View view) {
		// TODO Auto-generated method stub
		tvOupei = (TextView) view.findViewById(R.id.tv_oupei);
		tvYapan = (TextView) view.findViewById(R.id.tv_yapan);
		tvDaxia = (TextView) view.findViewById(R.id.tv_daxia);
		tvKaili = (TextView) view.findViewById(R.id.tv_kaili);
		tvOupei.setOnClickListener(this);
		tvYapan.setOnClickListener(this);
		tvDaxia.setOnClickListener(this);
		tvKaili.setOnClickListener(this);

	}

	public void changeFragment(int i) {
		FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
		if (i == 1) {
			tvId = R.id.tv_oupei;
			tvOupei.setBackgroundResource(R.color.main_red);
			tvYapan.setBackgroundResource(R.color.main_write);
			tvDaxia.setBackgroundResource(R.color.main_write);
			tvKaili.setBackgroundResource(R.color.main_write);

			tvOupei.setTextColor(activity.getResources().getColor(R.color.main_write));
			tvYapan.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvDaxia.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvKaili.setTextColor(activity.getResources().getColor(R.color.main_peilv));

		
			transaction.replace(R.id.fragment_container, PeilvOupeiFragment.newInstance(infoId,hid,gid,mainName,GuesName),"oupei");

			transaction.commitAllowingStateLoss();

		} else if (i == 2) {
			tvId = R.id.tv_yapan;
			tvOupei.setBackgroundResource(R.color.main_write);
			tvYapan.setBackgroundResource(R.color.main_red);
			tvDaxia.setBackgroundResource(R.color.main_write);
			tvKaili.setBackgroundResource(R.color.main_write);

			tvOupei.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvYapan.setTextColor(activity.getResources().getColor(R.color.main_write));
			tvDaxia.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvKaili.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			transaction.replace(R.id.fragment_container,  PeilvYapanFragment.newInstance(infoId,hid,gid,mainName,GuesName), "yapan");

			transaction.commitAllowingStateLoss();

		} else if (i == 3) {
			tvId = R.id.tv_daxia;
			tvOupei.setBackgroundResource(R.color.main_write);
			tvYapan.setBackgroundResource(R.color.main_write);
			tvDaxia.setBackgroundResource(R.color.main_red);
			tvKaili.setBackgroundResource(R.color.main_write);

			tvOupei.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvYapan.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvDaxia.setTextColor(activity.getResources().getColor(R.color.main_write));
			tvKaili.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			transaction.replace(R.id.fragment_container, PeilvDaxiaoFragment.newInstance(infoId,hid,gid,mainName,GuesName), "daxiao");
			transaction.commitAllowingStateLoss();

		} else  {
			tvId = R.id.tv_kaili;
			tvOupei.setBackgroundResource(R.color.main_write);
			tvYapan.setBackgroundResource(R.color.main_write);
			tvDaxia.setBackgroundResource(R.color.main_write);
			tvKaili.setBackgroundResource(R.color.main_red);

			tvOupei.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvYapan.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvDaxia.setTextColor(activity.getResources().getColor(R.color.main_peilv));
			tvKaili.setTextColor(activity.getResources().getColor(R.color.main_write));
			transaction.replace(R.id.fragment_container, PeilvKailiiFragment.newInstance(infoId,hid,gid,mainName,GuesName), "kaili");

			transaction.commitAllowingStateLoss();

		}
		ProgressDialogBar.stopProgress();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.tv_oupei:
			if (tvId != R.id.tv_oupei) {
				changeFragment(1);
			}
			break;
		case R.id.tv_yapan:
			if (tvId != R.id.tv_yapan) {
				changeFragment(2);
			}
			break;
		case R.id.tv_daxia:
			if (tvId != R.id.tv_daxia) {
				changeFragment(3);
			}
			break;
		case R.id.tv_kaili:
			if (tvId != R.id.tv_kaili) {
				changeFragment(4);
			}
			break;

		default:
			break;
		}
	}

}
